from common.mysql_operate import db

class Comment_store():
    def list(self,):
        sql = "SELECT * FROM comment"
        return db.select_db(sql)


    def getCommentByBlogId(self,blog_id):
        sql = "SELECT * FROM comment where blog_id = {}".format(blog_id)
        return db.select_db(sql)
    def countByBlogId(self,blog_id):
        sql = "SELECT COUNT(*) as count FROM `comment` WHERE blog_id = {}".format(blog_id)
        return db.select_db(sql)

    def addComment(self, comment):
        sql = "INSERT INTO `comment` VALUES(NULL,{},'{}','{}','{}')".format(comment.blog_id, comment.content,
                                                                            comment.created_time, comment.user_number)
        return db.execute_db(sql)

    def deleteCommentById(self,id):
        sql = "delete FROM `comment` WHERE id = {}".format(id)
        return db.execute_db(sql)
